<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>系统登录</title>
    <link rel="shortcut icon" href="static/image/logo01.ico"/>
    <link href="static/easyui/themes/default/easyui.css" rel="stylesheet">
    <link href="static/easyui/themes/icon.css" rel="stylesheet"
          type="text/css"/>
    <link href="static/login.css" rel="stylesheet"
          type="text/css"/>
    <script type="text/javascript" src="static/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
</head>
<body>
<div>
    <div id="formPanel">
        <div style="margin: 20px 0;"></div>
        <div class="easyui-panel" title="登录" style="width: 400px;height: 200px;">
            <div>
                <form id="loginForm">
                    <table>
                        <tr>
                            <td>账号：</td>
                            <td><input type="text" id="username"
                                       name="username"></input></td>
                        </tr>
                        <tr>
                            <td>密码：</td>
                            <td><input  type="password"
                                       id="password" name="password"></input></td>
                        </tr>
                    </table>
                </form>
                <div style="text-align: center; padding: 5px">
                    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
                       onclick="submitForm()">登录</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload'"
                       onclick="clearForm()">重置</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-man'"
                       onclick="toRegister()">注册</a>
                    <a href="javascript:void(0)" onclick="openWindow()">忘记密码</a>
                </div>
            </div>
        </div>
        <div id="win" class="easyui-window" title="My Window" style="width:600px;height:400px;"
             data-options="iconCls:'icon-save',modal:true,closed:true">
            <table>
                <tr>
                    <td>账号：</td>
                    <td>
                        <input class="easyui-textbox" type="text" id="username2"
                               name="username2"></input>
                    </td>
                </tr>
                <tr>
                    <td>邮箱：</td>
                    <td>
                        <input class="easyui-textbox" type="text" id="emailAddress"
                               name="emailAddress"></input>
                    </td>
                </tr>
            </table>
            <div style="padding: 5px">
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="sendEmail()">发送</a>
            </div>

        </div>
    </div>
</div>
<script>
  // 点击登录
  function submitForm() {
    var username = $("#username").val();
    var password = $("#password").val();
    $.ajax({
      type: "post",
      url: "login",
      data: {
        username: username,
        password: password
      },
      success: function (data) {
        if (data.code == 0) {
          $.messager.show({
            title: '消息提示',
            msg: data.message,
            timeout: 1000,
            showType: 'slide',
            style: {
              right: '',
              top: document.body.scrollTop + document.documentElement.scrollTop,
              bottom: ''
            }
          });
          if (username == 'admin') {
            document.location.href = "manage/admin/admin.jsp"
          } else {
            document.location.href = "manage/index.jsp"
          }
        } else {
          $.messager.show({
            title: '消息提示',
            msg: data.message,
            timeout: 1000,
            showType: 'slide',
            style: {
              right: '',
              top: document.body.scrollTop + document.documentElement.scrollTop,
              bottom: ''
            }
          });
        }
      }
    });

  }

  // 点击重置, 清空
  function clearForm() {
    $('#loginForm').form('clear');
  }

  // 点击注册, 跳转到注册页面
  function toRegister() {
    window.location.href = "register.jsp";
  }

  function openWindow() {
    $("#win").window('open');
  }

  // 向客户的邮箱发送邮件
  function sendEmail() {
    var username = $("#username2").val();
    var emailAddress = $("#emailAddress").val();
    console.log(username, emailAddress);
    $.ajax({
      url: "checkEmail",
      type: "post",
      data: {
        username: username,
        emailAddress: emailAddress
      },
      success: function (response) {
        if (response.code = 0) {
          $.messager.alert('提示信息', response.message + ",请前往邮箱查看", "info");
        } else {
          $.messager.alert('提示信息', response.message, "info");
        }
      }
    })
  }
</script>
</body>
</html>